# $NetBSD$

DISTNAME=		nix-2.15.0
CATEGORIES=		sysutils
MASTER_SITES=		${MASTER_SITE_GITHUB:=NixOS/}

MAINTAINER=		nikita@NetBSD.org
HOMEPAGE=		https://github.com/NixOS/nix/
COMMENT=		Purely functional package manager
LICENSE=		gnu-lgpl-v2.1

USE_TOOLS+=		pkg-config flex bash bison gmake
USE_TOOLS+=		automake autoconf autoreconf
USE_LANGUAGES=		c c++17
GNU_CONFIGURE=		yes

TOOL_DEPENDS+=		autoconf-archive-[0-9]*:../../devel/autoconf-archive

PKGCONFIG_OVERRIDE+=	src/libexpr/nix-expr.pc.in
PKGCONFIG_OVERRIDE+=	src/libmain/nix-main.pc.in
PKGCONFIG_OVERRIDE+=	src/libstore/nix-store.pc.in

.include "../../mk/bsd.prefs.mk"

# CONFIGURE_ARGS+=	--localstatedir=/nix/var
# CONFIGURE_ARGS+=	--with-sandbox-shell=/bin/sh
# CONFIGURE_ARGS+=	--enable-static=rapidcheck

# one of those fixes the detection of rapidcheck
CONFIGURE_ENV+=		RAPIDCHECK_HEADERS=${BUILDLINK_PREFIX.rapidcheck}/include/rapidcheck
CFLAGS+=		-I${BUILDLINK_PREFIX.rapidcheck}/include/rapidcheck
LDFLAGS+=		-L${BUILDLINK_PREFIX.rapidcheck}/lib

# s3 option needs s3-cpp, this was reported as a cause for error if
# left unchanged.
CONFIGURE_ENV+=		ac_cv_header_aws_s3_S3Client_h=no
#CONFIGURE_ENV+=	EDITLINE_CFLAGS=${BUILDLINK_PREFIX.editlinereadline:Q}/include
#CONFIGURE_ENV+=	EDITLINE_LIBS=-L${BUILDLINK_PREFIX.editlinereadline:Q}/lib
#CONFIGURE_ENV+=	EDITLINE_CFLAGS=-I${BUILDLINK_PREFIX.editlinereadline:Q}/include/readline
CONFIGURE_ENV+=		EDITLINE_CFLAGS="-DREADLINE"
#CONFIGURE_ENV+=	EDITLINE_LIBS="-ledit -L${BUILDLINK_PREFIX.editlinereadline}/lib"
CONFIGURE_ENV+=		EDITLINE_LIBS="-ledit -L${BUILDLINK_PREFIX.editline}/lib"
#CONFIGURE_ENV+=	EDITLINE_CFLAGS=${BUILDLINK_PREFIX.editline:Q}/include/readline
#CONFIGURE_ENV+=	EDITLINE_LIBS=${BUILDLINK_PREFIX.editline:Q}/lib
#CONFIGURE_ENV+=	LIBLZMA_CFLAGS="-I${BUILDLINK_PREFIX.xz:Q}/include"
#CONFIGURE_ENV+=	LIBLZMA_LIBS="-llzma -L${BUILDLINK_PREFIX.xz:Q}/lib"
CONFIGURE_ENV+=		BOOST_ROOT=${BUILDLINK_PREFIX.boost-libs}/lib

# Workaround for:
#   /usr/bin/ld: error: undefined symbol: SHA512_Update
MAKE_FLAGS+=	libutil_ALLOW_UNDEFINED=yes

# sqlite3_error_offset(), https://www.sqlite.org/releaselog/3_38_0.html
BUILDLINK_API_DEPENDS.sqlite3+=	sqlite3>=3.38

BUILDLINK_TRANSFORM.NetBSD+=	rm:-ldl

# verbose build
MAKE_ENV+=	V=1
# Disable hardcoded -O3
MAKE_ENV+=	OPTIMIZE=0

# checking for aws/s3/S3Client.h... (cached) no
# ./configure: 7863: Syntax error: "(" unexpected (expecting "fi")
# *** Error code 2
# hack configure.ac bashism, work on an upstream fix for this,
# thanks 0mp@FreeBSD.org for this tiny detail:
CONFIG_SHELL=		${TOOLS_PATH.bash}

# incomplete, remove once the docs build
CONFIGURE_ARGS+=	--disable-doc-gen

# Buildusers
PKG_GROUPS+=	nixbld
.for i in 1 2 3 4 5 6 7 8 9 10
PKG_USERS+=	nixbld${i}:nixbld
.endfor

#SUBST_CLASSES+=	docbook
#SUBST_MESSAGE.docbook=	Fixing docbook URLs.
#SUBST_FILES.docbook+=	doc/manual/installation/prerequisites-source.xml
#SUBST_FILES.docbook+=	doc/manual/local.mk
#SUBST_FILES.docbook+=	doc/manual/manual.xml
#SUBST_STAGE.docbook=	pre-configure
#SUBST_SED.docbook+=	-e 's,http://docbook.sourceforge.net/release/xsl/current,${PREFIX}/share/xsl/docbook,g'

# and one more.
# SUBST_CLASSES+=		docbook2
# SUBST_MESSAGE.docbook2=	Fixing docbook URLs.
# SUBST_FILES.docbook2+=	doc/manual/local.mk
# SUBST_STAGE.docbook2=		pre-configure
# SUBST_SED.docbook2+=		-e 's,http://docbook.org/xml/5.0/rng/docbook.rng,${PREFIX}/share/xsl/docbook,g'

TOOL_DEPENDS+=	libxslt-[0-9]*:../../textproc/libxslt
TOOL_DEPENDS+=	docbook-xsl-[0-9]*:../../textproc/docbook-xsl
TOOL_DEPENDS+=	jq-[0-9]*:../../devel/jq

# Linux is supported, FreeBSD support is experimental.
# macOS is probably supported.
# Whoever updates this package and maybe imports it
# should declare other OS as unsupported.

#.if ${OPSYS} == "NetBSD"
#USE_BUILTIN.editline=	yes
#READLINE_DEFAULT=	readline
#.endif

#.include "../../mk/readline.buildlink3.mk"
# .if ${READLINE_TYPE} == "readline"
# SUBST_CLASSES+=		editline
# SUBST_MESSAGE.editline=	Fixing editline header.
# SUBST_STAGE.editline=		pre-configure
# SUBST_FILES.editline=		src/nix/repl.cc
# SUBST_SED.editline=		-e "s,editline\.h,readline\.h,g"
# .endif

pre-configure:
	cd ${WRKSRC} && ${SH} bootstrap.sh

#.include "../../archivers/lzmalib/buildlink3.mk"
#.include "../../mk/dlopen.buildlink3.mk"
.include "../../archivers/brotli/buildlink3.mk"
.include "../../archivers/bzip2/buildlink3.mk"
.include "../../archivers/libarchive/buildlink3.mk"
.include "../../archivers/xz/buildlink3.mk"
.include "../../databases/sqlite3/buildlink3.mk"
.include "../../devel/boehm-gc/buildlink3.mk"
.include "../../devel/boost-libs/buildlink3.mk"
.include "../../devel/editline/buildlink3.mk"
.include "../../devel/googletest/buildlink3.mk"
.include "../../devel/rapidcheck/buildlink3.mk"
.include "../../sysutils/libcpuid/buildlink3.mk"
.include "../../security/libsodium/buildlink3.mk"
.include "../../security/openssl/buildlink3.mk"
.include "../../textproc/nlohmann-json/buildlink3.mk"
.include "../../textproc/lowdown/buildlink3.mk"
.include "../../www/curl/buildlink3.mk"
#.include "../../wip/aws-sdk-cpp/buildlink3.mk" # Needs some source fixes
.include "../../mk/bsd.pkg.mk"
